package com.heima.zuoye.day12.timu4;

import javax.annotation.processing.Filer;
import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Demo1 {
    public static void main(String[] args) throws Exception {
        FileReader fr = new FileReader("D:\\JAVA\\JavaSE进阶-相关资料\\课后作业\\day10\\hero.txt", Charset.forName("GBK"));
        BufferedReader br = new BufferedReader(fr);
        String s = br.readLine();
        String str;
        ArrayList<Hero> list = new ArrayList<>();
        while ((str = br.readLine()) != null) {
            String[] sp = str.split(",+");
            Hero hero = new Hero(sp[0], Integer.parseInt(sp[1]), Integer.parseInt(sp[2]), Integer.parseInt(sp[3]));
            list.add(hero);
        }
        br.close();
        System.out.println(list);
        Collections.sort(list, new Comparator<Hero>() {
            @Override
            public int compare(Hero o1, Hero o2) {
                return Double.compare(o2.getShi(), o1.getShi());
            }
        });
        System.out.println(list);
        FileWriter fw = new FileWriter("D:\\JAVA\\JavaSE进阶-相关资料\\课后作业\\day10\\hero2.txt", Charset.forName("GBK"));
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(s + "    新手适应分值");
        bw.newLine();
        for (Hero hero : list) {
            bw.write(hero.getName() + "," + hero.getSheng() + "," + hero.getGong() + "," + hero.getXiao() + "," + hero.getShi());
            bw.newLine();
        }
        bw.close();
    }
}
